package com.example.s.adapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

public abstract class MyCommonViewAdapter<T> extends PagerAdapter {
    List<T> list;

    public MyCommonViewAdapter(List<T> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size() ;
    }



    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        Log.d("MyLoopViewAdapter", "instantiateItem: "+position + " list.size = "+list.size());
        return handleData(container, position);
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    public abstract Object handleData(ViewGroup container, int pos);
}
